package com.cqch.controller;

import com.cqch.pojo.repVo.BaseResp;
import com.cqch.pojo.reqVo.UserReqVo;
import com.cqch.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author CQCH
 * @Description
 * @Date 2022/3/28
 */
@CrossOrigin
@RestController
@RequestMapping("/user")  //用户端口
public class UserController {

    @Autowired
    UserService userService;

    /**
     * 验证登录名是否被占用
     * @param userReqVo
     * @return
     */
    @RequestMapping("/validataloginName")
    public BaseResp validataloginName(@RequestBody UserReqVo userReqVo){
        return userService.validataloginName(userReqVo);
    }
    @RequestMapping("/validataPhone")
    public BaseResp validataPhone(@RequestBody UserReqVo userReqVo){
        return userService.validataPhone(userReqVo);
    }

    /**
     * 发送邮件
     */

    @RequestMapping("/getCode")  //需要
    public BaseResp getCode(@RequestParam("mail")String mail){

        return userService.getCode(mail);
    }

    /**
     * 注册接口
     * @param
     * @return
     */
    @RequestMapping("/registry")
    public BaseResp registry(@RequestBody UserReqVo userReqVo){

        return userService.registry(userReqVo);
    }

    /**
     * 登录接口
     * @param
     * @return
     */
    @RequestMapping("/login")
    public BaseResp login(@RequestBody UserReqVo userReqVo){
        return userService.login(userReqVo);
    }

    /**
     * 通过token获取到用户
     */
    @RequestMapping("/findUserByToken")
    public BaseResp findUserByToken(HttpServletRequest request){
        return userService.findUserByToken(request);
    }

    /**
     *  手机号 验证码
     */
    @RequestMapping("/phone")
    public BaseResp phone(@RequestBody Map map) {
        Object phone = map.get("phone");
        return userService.phone(phone.toString());
    }

    /**
     *  手机号注册功能
     */
    @RequestMapping("/registryPhone")
    public BaseResp registryPhone(@RequestBody UserReqVo userReqVo) {
        return userService.registryPhone(userReqVo);
    }
    /**
     *  手机号登录功能
     */
    @RequestMapping("/loginPhone")
    public BaseResp loginPhone(@RequestBody UserReqVo userReqVo) {
        return userService.loginPhone(userReqVo);
    }

    /**
     *  邮箱登录功能
     */
    @RequestMapping("/loginEmail")
    public BaseResp loginEmail(@RequestBody UserReqVo userReqVo) {
        return userService.loginEmail(userReqVo);
    }
}
